home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / Preinstalled MacPerl (FAT) / t / op / eval.t < prev    next >
Encoding:
Text File  |  1995-07-02  |  1.3 KB  |  59 lines  |  [TEXT/McPL]

  1. #!./perl
  2.  
  3. # $RCSfile: eval.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:48 $
  4.  
  5. print "1..16\n";
  6.  
  7. eval 'print "ok 1\n";';
  8.  
  9. if ($@ eq '') {print "ok 2\n";} else {print "not ok 2\n";}
  10.  
  11. eval "\$foo\n    = # this is a comment\n'ok 3';";
  12. print $foo,"\n";
  13.  
  14. eval "\$foo\n    = # this is a comment\n'ok 4\n';";
  15. print $foo;
  16.  
  17. print eval '
  18. $foo =;';        # this tests for a call through yyerror()
  19. # if ($@ =~ /line 2/) {print "ok 5\n";} else {print "not ok 5\n";}
  20. if ($@ =~ /Line 2/) {print "ok 5\n";} else {print "not ok 5\n";}
  21.  
  22. print eval '$foo = /';    # this tests for a call through fatal()
  23. if ($@ =~ /Search/) {print "ok 6\n";} else {print "not ok 6\n";}
  24.  
  25. print eval '"ok 7\n";';
  26.  
  27. # calculate a factorial with recursive evals
  28.  
  29. $foo = 5;
  30. $fact = 'if ($foo <= 1) {1;} else {push(@x,$foo--); (eval $fact) * pop(@x);}';
  31. $ans = eval $fact;
  32. if ($ans == 120) {print "ok 8\n";} else {print "not ok 8\n";}
  33.  
  34. $foo = 5;
  35. $fact = 'local($foo)=$foo; $foo <= 1 ? 1 : $foo-- * (eval $fact);';
  36. $ans = eval $fact;
  37. if ($ans == 120) {print "ok 9\n";} else {print "not ok 9 $ans\n";}
  38.  
  39. open(try,'>Op.eval');
  40. print try 'print "ok 10\n"; unlink "Op.eval";',"\n";
  41. close try;
  42.  
  43. do 'Op.eval'; print $@;
  44.  
  45. # Test the singlequoted eval optimizer
  46.  
  47. $i = 11;
  48. for (1..3) {
  49.     eval 'print "ok ", $i++, "\n"';
  50. }
  51.  
  52. eval {
  53.     print "ok 14\n";
  54.     die "ok 16\n";
  55.     1;
  56. } || print "ok 15\n$@";
  57.  
  58.  
  59.